package dobest.ray.com.jiongjiong.activity.wanttoknow;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

import dobest.ray.com.jiongjiong.R;
import dobest.ray.com.jiongjiong.activity.BaseFragment;
import dobest.ray.com.jiongjiong.activity.action.service.ServiceActivity;
import dobest.ray.com.jiongjiong.activity.wanttoknow.consult.ConsultOnlineOneActivity;
import dobest.ray.com.jiongjiong.activity.wanttoknow.professionalSpeaker.ProfessionalSpeakerActivity;
import dobest.ray.com.jiongjiong.adapter.WantToKnowBaseAdapter;
import dobest.ray.com.jiongjiong.views.NavigationBar;

/**
 * Created by Ray on 2016/3/16.
 * https://github.com/ray0807
 * 行动起来
 */
public class WantToKnowFragment extends BaseFragment implements View.OnClickListener {
    private NavigationBar navi;
    private PullToRefreshListView ptr_list;
    /**
     * activity 实例
     */
    private Activity mActivity;
    private WantToKnowBaseAdapter adapter;
    private View header;

    private LinearLayout ll_consult_online;
    private LinearLayout ll_professional_speaker;



    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mActivity = getActivity();
        header = inflater.inflate(R.layout.header_want_to_know, null);
        return inflater.inflate(R.layout.fragment_want_to_know, container, false);
    }

    @Override
    protected void findViews(View view) {
        navi = (NavigationBar) view.findViewById(R.id.navi);
        navi.setTitle("想知道");
        ptr_list = (PullToRefreshListView) view.findViewById(R.id.ptr_list);
        ll_consult_online = (LinearLayout) header.findViewById(R.id.ll_consult_online);
        ll_professional_speaker = (LinearLayout) header.findViewById(R.id.ll_professional_speaker);

    }

    @Override
    protected void init() {
        ptr_list.setMode(PullToRefreshBase.Mode.BOTH);
        adapter = new WantToKnowBaseAdapter(mActivity);
        ptr_list.setAdapter(adapter);
        ptr_list.getRefreshableView().addHeaderView(header);
    }

    @Override
    protected void addListeners() {
        ll_consult_online.setOnClickListener(this);
        ll_professional_speaker.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        Intent it = null;
        switch (v.getId()) {
            case R.id.ll_consult_online:
                it = new Intent(mActivity, ConsultOnlineOneActivity.class);
                break;
            case R.id.ll_professional_speaker:
                it = new Intent(mActivity, ProfessionalSpeakerActivity.class);
                break;

        }
        if (it != null) {
            mActivity.startActivity(it);
        }
    }
}
